package com.sky.controller.user;

import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * SetmealController
 *
 * @author liliudong
 * @version 1.0
 * @description 套餐控制器
 * @date 2023/7/31 18:50
 */
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@RequiredArgsConstructor
public class SetmealController {

    private final SetmealService setmealService;

    /**
     * 列表
     *
     * @param categoryId 类别id
     * @return {@link Result}<{@link List}<{@link Setmeal}>>
     */
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmeals", key = "#categoryId")
    public Result<List<Setmeal>> list(Long categoryId) {
        List<Setmeal> setmeals = setmealService.listByCategoryId(categoryId);
        return Result.success(setmeals);
    }

    /**
     * 列表菜
     *
     * @param setmealId setmeal id
     * @return {@link Result}<{@link List}<{@link Dish}>>
     */
    @GetMapping("/dish/{setmealId}")
    public Result<List<SetmealDish>> listDish(@PathVariable Long setmealId) {
        List<SetmealDish> setmealDishList = setmealService.listDishById(setmealId);
        return Result.success(setmealDishList);
    }
}
